var NewProject = {
    ele_add_container: document.getElementById('add_container'),
    ele_check_container: document.getElementById('check_container'),
    ele_done_container: document.getElementById('done_container'),
    
    ele_check_err: document.getElementById('err_check'),
    ele_check_img: document.getElementById('img_check_status'),
    ele_check_ib: document.getElementById('ib_text_nametocheck'),
    ele_check_submit: document.getElementById('submit_check'),
    ele_check_spinner: document.getElementById(''),
    ele_check_blocker: document.getElementById('checker_blocker'),
    ele_add_hidden: document.getElementById('hidden_text_alias'),
    ele_add_name: document.getElementById('add_name'),
    ele_add_name_count: document.getElementById('add_name_count'),
    ele_add_desc: document.getElementById('add_desc'),
    ele_add_submit: document.getElementById('add_submit'),
    ele_add_err: document.getElementById('err_add'),
    step_one: false,
    step_two: false,
    
    init: function() {
	
    },
    
    setHiddenProjectAlias: function(newvalue) {
	NewProject.ele_add_hidden.value = newvalue;
    },
    
    activate_one: function() {
	if(NewProject.step_one == true) {
	    EMDE.enableElement(NewProject.ele_check_submit, true);
	    EMDE.enableElement(NewProject.ele_check_ib, true);
	    NewProject.ele_check_img.src = '/img/ok.png';
	    NewProject.setHiddenProjectAlias(NewProject.ele_check_ib.value);
	    NewProject.activate_two();
	} else {
	    EMDE.enableElement(NewProject.ele_check_submit, false);
	    EMDE.enableElement(NewProject.ele_check_ib, false);
	    NewProject.ele_check_img.src = '/img/not_ok.png';
	    NewProject.setHiddenProjectAlias('');
	}
    },
    
    activate_two: function() {
	EMDE.showElement(NewProject.ele_add_container);
    },
    
    check_callback: function(boolIn) {
	NewProject.step_one = boolIn;
	NewProject.activate_one();
    },
    
    add_callback: function(boolIn) {
	if(boolIn == true) {
	    EMDE.hideElement(NewProject.ele_add_container);
	    EMDE.hideElement(NewProject.ele_check_container);
	    EMDE.showElement(NewProject.ele_done_container);
	}
    },
    
    canadd: function() {
	var valName = NewProject.ele_add_name.value;
	var valDesc = NewProject.ele_add_desc.value;
	if(valName.toString().length < 128 && valName.toString().length > 0 && valDesc.toString().length > 0 && NewProject.step_one) {
	    NewProject.ele_add_submit.disabled = false;
	} else {
	    NewProject.ele_add_submit.disabled = true;
	}
    },
    
    addnamecheck: function() {
	var val = NewProject.ele_add_name.value;
	if(val.toString().length > 128) {
	    NewProject.ele_add_name.style.background = "#ff7777";
	} else {
	    NewProject.ele_add_name.style.background = "#ffffff";
	}
	NewProject.ele_add_name_count.innerHTML = parseInt(128 - val.toString().length);
	NewProject.canadd();
    },
    
    adddesccheck: function() {
	NewProject.canadd();
    },
    
    navigate: function() {
	window.location = '/edit/' + NewProject.ele_add_hidden.value;
    },
    
    invalidFormat: function(erString) {
	if(erString == false) {
	    EMDE.hideElement(NewProject.ele_check_err);
	    NewProject.ele_check_err.innerHTML = "";
	} else {
	    EMDE.showElement(NewProject.ele_check_err);
	    NewProject.ele_check_err.innerHTML = '<br />' + erString;
	}
    },
    
    alreadyTaken: function(erString) {
	if(erString == false) {
	    EMDE.hideElement(NewProject.ele_add_err);
	    NewProject.ele_add_err.innerHTML = "";
	} else {
	    EMDE.showElement(NewProject.ele_add_err);
	    NewProject.ele_add_err.innerHTML = '<br />' + erString;
	}
    }
};